<script>
function load_page(){
	$('#insure').html('<img style=\'margin-top:100px;\' src=\'images/loading.gif\' align="absmiddle"/>'); 
	$.get(
		'insure_ajax.php',
		function(data){
			$('#insure').html(data).hide().fadeIn('fast');;
			$('ul#icons li').hover(
				function() { $(this).addClass('ui-state-hover'); }, 
				function() { $(this).removeClass('ui-state-hover'); 
			});
			fgbutton();
	});
}
$(function(){
	load_page();
	
	$('#company').change(function(){
		$('#insure').html('<img style=\'margin-top:100px;\' src=\'images/loading.gif\' align="absmiddle"/>'); 
		$.get('insure_ajax.php',{company:$('#company').val(),type:$('#type').val()},
			function(data){
				$("#insure").html(data).hide().fadeIn('slow');;
			}
		);
	});
	
	$('#type').change(function(){
		$('#insure').html('<img style=\'margin-top:100px;\' src=\'images/loading.gif\' align="absmiddle"/>'); 
		$.get('insure_ajax.php',{type:$('#type').val(),company:$('#company').val()},
			function(data){
				$("#insure").html(data).hide().fadeIn('slow');;
			}
		);
	});
});

function active(id,status)
{
	$("#dialog_active").dialog({
		modal: true,
		buttons: {
			ตกลง: function() {
					$.get(
						'insure_control.php',
						{id:id,status:status,action:'active'},
						function(data){
							if(status == 'online'){
								$('#active'+id).html("<a onclick=\"active("+id+",'offline')\" href=\"javascript:void(0);\"><span style=\"color:black;\">offline</span></a>").hide().fadeIn('slow');
							}else{
								$('#active'+id).html("<a onclick=\"active("+id+",'online')\" href=\"javascript:void(0);\"><span style=\"color:green;\">online</span></a>").hide().fadeIn('slow');
							}
					});
					$( this ).dialog( "close" );
				},
			ยกเลิก:function() {
					$( this ).dialog( "close" );
				}
		}
	});
}
function EditData(id,mode)
{
	$.get(
		'insure_view.php',
		{id:id,action:mode},
		function(data){
			$('#insure_dialog').html(data);
		}
	);
	$("#insure_dialog").dialog({
		modal: true,
		width:400,
		position:'top',
		buttons: {
			ตกลง: function(){
				$.post('insure_view.php',$('form#editinsure').serialize(),function(data){
					if(data!=''){
						$('#msg').html(data);
						$('#dialog').dialog({
							model:true,
							buttons:{
								ตกลง:function(){
									$( this ).dialog( "close" );
								}
							}
						});
					}else{
						$('#insure_dialog').dialog( "close" );
						load_page();
					}
				});
				$( this ).dialog( "close" );
			},
			ยกเลิก:function(){
				$( this ).dialog( "close" );
			}
		}
	});
}
function DeleteData(id)
{
	$("#dialog2").dialog({
		modal: true,
		width:400,
		buttons: {
			ตกลง: function(){
				$.get('member_control.php',{id:id,action:'delete_insure'},function(data){load_page();});
				$( this ).dialog( "close" );
			},
			ยกเลิก:function(){
				$( this ).dialog( "close" );
			}
		}
	});
}
</script>
<div id="dialog_active" title="ข้อความ"  style="display:none;">
	<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>ต้องการเปลี่ยนสถานะ?</p>
</div>
<div id="dialog2" title="ข้อความ"  style="display:none;">
	<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>ต้องการลบข้อมูล?</p>
</div>
<div id="insure_dialog" title="ข้อมูลสมาชิก"  style="display:none;"></div>
<div id="tabs">
    <ul>
    	<li><a class="head_tab" style="padding-left:7px;" href="#tabs-1"><span class="ui-icon ui-icon-person" style="float:left;"></span>ประกันภัย</a></li>
    </ul>
    <div id="tabs-1">
        	<ul id="panel">
                <li>
                	 <select name="type" id="type">
                          <option selected="selected" value="">เลือกประเภท</option>
                          <?php
                                $sql_t = "select * from tb_insure_type order by id asc";
                                $qr_t = select($sql_t);
                                $j=0;
                                while($j<count($qr_t))
                                {
                                    $rs_t = $qr_t[$j];
                                    $j++;
                            ?>
                            <option value="<?php echo $rs_t['id'] ?>"><?php echo $rs_t['name'];?></option>
                            <?php
                                }
                            ?>
     			 </select>	
           </li>
           <li>
           		<select name="company" id="company" >
                  <option selected="selected" value="">เลือกตามบริษัท</option>
                  <?php
                        $sql_t = "select * from tb_company order by id asc";
                        $qr_t = select($sql_t);
                        $j=0;
                        while($j<count($qr_t))
                        {
                            $rs_t = $qr_t[$j];
                            $j++;
                    ?>
                    <option value="<?php echo $rs_t['id'] ?>"><?php echo $rs_t['company_name'];?></option>
                    <?php
                        }
                    ?>
                  </select>
           </li>
                <div style="clear:both;"></div>
       </ul>
    	<div id="insure" align="center"></div>          
    </div>
</div>            